package com.qf.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/img/11.jpg")
@CrossOrigin
public class TestController {

    @GetMapping
    public String test(HttpServletRequest request){

        String ip = request.getRemoteAddr();
        System.out.println("获取到的IP是:" + ip);

        //X-Real-IP $remote_addr;
        String realIp = request.getHeader("X-Real-IP");
        System.out.println("浏览器的真实IP:" + realIp);

        //X-Forwarded-For  流经所有代理的IP ,隔开的
        String XForwardedFor = request.getHeader("X-Forwarded-For");
        System.out.println("流经所有代理的IP:" + XForwardedFor);
        String[] ips = XForwardedFor.split(",");
        System.out.println("多级代理情况下：真实IP:" + ips[0]);


        return "OK";
    }
}
